#include<iostream>
using namespace std;
int num=0;
int n, m, a[10], b[10],c[10][10];
int visited_row[10][10]={0}, visited_col[10][10]={0};

bool check(int aa[])
{
    int len = sizeof(aa) / sizeof(aa[0]);
    for(int i=0; i<len; i++)
        if(!aa[i])
            return false;
    return true;
}

void dfs(int x, int y) 
{
    if (num > 1)    return;
    if (x == n)
        if(check(a))
            num++;
    else if (y == m)
        dfs(x+1, 0);
    else if (!c[x][y])
        dfs(x, y+1);
    else 
    {
        for (int i = 1; i <= 9; i++)
        {
            if (!visited_row[x][i] && !visited_col[y][i] && a[x]-i >= 0 && b[y]-i >= 0)
                c[x][y] = i;
                visited_row[x][i] = 1;
                visited_col[y][i] = 1;
                a[x] -= i;
                b[y] -= i;
                dfs(x, y+1);
                c[x][y] = 0;
                visited_row[x][i] = 0;
                visited_col[y][i] = 0;
                a[x] += i;
                b[y] += i;
        }
    }
}

int main () 
{
    int T;
    cin >> T;
    while(T--) 
    {
        cin >> n >> m;
        for (int i=0; i<n; i++) cin >> a[i];
        for (int i=0; i<m; i++) cin >> b[i];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                cin >> c[i][j];
                int temp = c[i][j];
                if (temp)
                {
                    visited_row[i][temp] = 1;
                    visited_col[j][temp] = 1;
                    a[i] -= temp;
                    b[j] -= temp;
                }
            }
        }
        dfs(0, 0);
        if (!num)
            cout << "No answer.";
        if (num > 1)
            cout << "Not unique.";
        if (num == 1)
            for (int i = 0; i < n; i++) 
            {
                for (int j = 0; j < m-1; j++)
                    cout << c[i][j] << " ";
                cout << c[i][m-1] << endl;
            }
    }
    return 0;
}